package indigo.loader.loaders 
{
	import indigo.loader.types.LoaderTypes;
	import indigo.utils.IDisposable;

	import flash.events.Event;
	/**
	 * @author Patrick Pietens
	 *
	 */
	public class LoadActor implements IDisposable
	{
		/**
		 * String that indicates the filename
		 */
		public var filename:String;
		/**
		 * AbstractLoader that is used to laod the file
		 */
		public var loader:AbstractLoader;

		
		/**
		 * Constructor
		 * @param String that indicates the filename
		 */
		public function LoadActor( filename:String )
		{
			this.filename = filename;
			this.createLoader( );
		}

		
		private function createLoader():void
		{
			switch ( LoaderTypes.getLoaderType( this.filename ) )
			{
				case LoaderTypes.BINARY: 
					this.loader = new BinaryLoader( ); 
					break;
				case LoaderTypes.IMAGE: 
					this.loader = new ImageLoader( ); 
					break;
				case LoaderTypes.SWF: 
					this.loader = new SWFLoader( ); 
					break;
				case LoaderTypes.VIDEO:	
					this.loader = new FLVLoader( ); 
					break;
				case LoaderTypes.SOUND: 
					this.loader = new SoundLoader( );
					break;
				case LoaderTypes.TEXT: 
					this.loader = new TextLoader( ); 
					break;
					//			case LoaderTypes.UNKNOWN:
					//				// Load unknown as a binary file 
					//				if ( this.loadUnknownAsBinary )
					//						this.loader = new BinaryLoader( );
					//						
					//					// Throw an error
					//					else
					//						throw new LoadError( LoadError.LOADER_FILE_TYPE_NOT_SUPPORTED ); 
					break;
			}		
		}

		
		/**
		 * @inheritDoc
		 * 
		 */
		public function dispose( event:Event = null ):void
		{
			this.loader.dispose( event );
			this.loader = null;
		}
	}		
}